#ifndef RESOURCEMANAGER_H
#define RESOURCEMANAGER_H

#include <iostream>
#include <exception>
#include <vector>
#include <string>
#include "Export.h"
#include "IResource.h"
using namespace std;
namespace glow
{
	typedef std::vector<IResource*> tableR;
	
	class SHARED ResourceManager 
	{ 
		public :
   
		/**
		 *  Get the Ressource
		 *\param filename the name of the file added to the manager
		 **/
		template<class T>
		inline T *get(std::string filename)
		{
			/* on vérifie si la ressource est déja chargé dans le manager */
			unsigned int n = _allR.size();
			unsigned int i;
			bool found = false;
			T* newR = NULL; 
			for (i = 0; i<n && !found ; i++)
				if (_allR[i]->getName() == filename)
					found = true;
			if (found)
			{
				newR = static_cast<T*>(_allR[i-1]);
				newR->addRef();
			}
			return newR;
		}
   
		/**
		 *  Set the ressource
		 *\param ressource the ressource added to the manager
		 **/
		void add(IResource *resource);
		
		/**
		 *  Remove the ressource
		 *\param name the name of the IRessource removed
		 **/
		void remove(std::string name);
		
		/**
		 *  SINGLETON : return the current instance
		 *\return the pointer to the current instance (SINGLETON)
		 **/
		static ResourceManager *getInstance();
		
		/**
		 *  SINGLETON : call the destructor of the current instance
		 **/
		static void destroy();

		private :
		
		/**
		 *  SINGLETON : default constructor
		 **/
		ResourceManager();
		
		/**
		 *  Delete the current instance
		 **/
		~ResourceManager();

		/**
		 *  Table of ressources
		 **/
		tableR _allR;
		
		/**
		 *  SINGLETON : Pointer to the current instance
		 **/
		static ResourceManager *_inst;
 };
}
#endif   
   
